package com.demo.demo01.controller;

import com.demo.demo01.mapper.CommentMapper;
import com.demo.demo01.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CommentController {

    @Autowired
    private CommentMapper commentMapper;

    @GetMapping("/queryCommentList")
    public List<Comment> queryComment(){
        List<Comment> commentList = commentMapper.queryComment();
        System.out.println(commentList);
        return commentList;
    }

    @GetMapping("/addComment")
    public int addComment(Comment comment){
        comment.setCode("" + countComment());
        return commentMapper.addComment(comment);
    }

    private int countComment(){
        return commentMapper.countComment();
    }


}
